package Server.Model.Hall;

import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import org.hyperic.sigar.SigarException;

import Server.Agent.CHttpClient;
import Server.Agent.GameAgent;
import Server.Model.Base.IRoom;
import Server.Model.Base.OtherRoom;
import Server.Model.Base.SHMUser;
import admin.AdminRedis;
import club.ClubMgr;
import club.ClubRedis;
import common.routine.CommonZooListener;
import common.routine.GlobalRoutine;
import common.routine.GlobalSetting;
import common.routine.MonitorInfoBean;
import common.routine.NodeInfoVo;
import common.routine.SystemInfo;
import common.routine.SystemInfoTools;
import common.routine.CommonDef.NodeType;
import logic.iface.LogicServer;
import net.sf.json.JSONObject;
import network.handler.NodePeerMgr;

public class QpGameMgr {
	private static QpGameMgr _instance = null;

	public Map<Integer, IRoom> m_mapUserRoom = new HashMap<Integer, IRoom>();
	public Map<Integer, WeakReference<IRoom>> m_mapFZ = new HashMap<Integer, WeakReference<IRoom>>();
	public Map<Integer, IRoom> m_mapRoom = new HashMap<Integer, IRoom>();

	public double m_gateCpuRateThreadHold = 50.0;
	public static QpGameMgr getInstance(){
		if(_instance == null){
			_instance = new QpGameMgr();
			_instance.init();
		}
		return _instance;
	}
	private void init(){
		//初始化棋牌管理器
		if(GlobalSetting.getInstance().getSelfNodeInfo().nodeType == NodeType.LOGIC){
			startHeartCheckTask();
			startNoUseRoomCheck();
			startCheckRoomZooInfo();
		}
	}
	public void onDealRoom(){
		try{
			Iterator<Map.Entry<Integer, IRoom>> itRoom = m_mapRoom.entrySet().iterator();
			while (itRoom.hasNext()) {
				Map.Entry<Integer, IRoom> entry = itRoom.next();
				IRoom value = entry.getValue();
				value.OnDeal(1000);
			}
		}catch(Exception e){
			//这里不做处理，解散房间冲突，添加一个同步锁也可以
		}
	}
	public void onUserClientCloseForRoom(int uid){
		if (m_mapUserRoom.containsKey(uid)) {
			IRoom tbl = m_mapUserRoom.get(uid);
			if (tbl != null) {
				tbl.OnClientClose(uid);
			}
		}
	}
	public boolean hasUsedRoomExist(){
		return m_mapRoom.size() != 0 && m_mapUserRoom.size() != 0;
	}
	public boolean isUserInRoom(int uid){
		return m_mapUserRoom.containsKey(uid);
	}
	public int getUserInRoomId(int uid){
		return m_mapUserRoom.get(uid).GetID();
	}
	public void removeUserRoom(int uid){
		m_mapUserRoom.remove(uid);
	}
	public IRoom getRoomById(int roomid){
		return m_mapRoom.get(roomid);
	}
	public void removeRoomById(int roomid){
		m_mapRoom.remove(roomid);
	}
	public IRoom getUserRoomByUid(int uid){
		return m_mapUserRoom.get(uid);
	}
	public void putRoomIntoMap(int roomid,IRoom room){
		m_mapRoom.put(roomid, room);
	}
	public void Handle_OnHeart(GameAgent agent, JSONObject root) {
		Integer _Uid = agent.getUid();
		if(_Uid == 0)
			return;
		long time = System.currentTimeMillis();
		SHMUser shmuser = dthall.getInstance().getUserInfo(_Uid);
		if (shmuser == null)
			return;
		if(shmuser.getHeartTime() == 0 && m_mapUserRoom.containsKey(shmuser.m_lUid)){
			IRoom room = m_mapUserRoom.get(shmuser.m_lUid);
			String gameType = room.GetType();
			JSONObject json = new JSONObject();
			if(gameType.equals("DDZ")){
				json.put("command","ddzmsg");
			}else if(gameType.equals("PDK")){
				json.put("command","pdkmsg");
			}else if(gameType.equals("NTPDK")){
				json.put("command","ntpdkmsg");
			}else if(gameType.equals("CP")){
				json.put("command","cpmsg");
			}else if(gameType.equals("SJ")){
				json.put("command","sjmsg");
			}else if(gameType.equals("BJ") || gameType.equals("LABJ")){
				json.put("command", "bjzmsg");
			}else if(gameType.equals("TTZ")){
				json.put("command","ttzmsg");
			}else if(gameType.equals("NIUNIU")){
				json.put("command", "niuniumsg");
			}else if(gameType.equals("SSZLIU")){
				json.put("command", "sszliumsg");
			}else if(gameType.equals("SSZ")){
				json.put("command", "sszmsg");
			}else if(gameType.equals("FJSSZ")){
				json.put("command", "fjsszmsg");
			}else if(gameType.equals("SLHB")){
				json.put("command", "slhbmsg");
			}else if(gameType.equals("CQSSC")){
				json.put("command", "cqsscmsg");
			}else if(gameType.equals("PK10")){
				json.put("command", "pk10msg");
			}else if(gameType.equals("AZXY5")){
				json.put("command", "azxy5msg");
			}else{
				json.put("command","mjmsg");
			}
			json.put("v", 1);
			json.put("uid",shmuser.m_lUid);
			json.put("data","inFore|0");
			if(agent != null){
				dthall.getInstance().OnRecv(agent, json);
			}
		}
		shmuser.setHeartTime(time);
	}
	public int Handle_OnGetCurrPlayingUserNum(){
		int count = 0;
		Iterator<Map.Entry<Integer, GameAgent>> itGamer = GameAgent.agents.entrySet().iterator();
		while (itGamer.hasNext()) {
			Map.Entry<Integer, GameAgent> agents = itGamer.next();
			if(agents != null){
				GameAgent agent = agents.getValue();
				if(agent != null){
					SHMUser value = agent.user;
					if(value != null){
						if(m_mapUserRoom.containsKey(value.getUid())){
							IRoom room = m_mapUserRoom.get(value.getUid());
							if(room.getDealTime() != 0)
								count++;
						}
					}
				}
			}
		}
		return count;
	}
	public int Handle_OnGetCurrPlayingRoomNum(){
		int count = 0;
		Iterator<Map.Entry<Integer, IRoom>> itRoom = m_mapRoom.entrySet().iterator();
		while (itRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itRoom.next();
			IRoom value = entry.getValue();
			int dealTime = value.getDealTime();
			if(dealTime != 0){
				count++;
			}
		}
		return count;
	}
	public int Handle_OnGetCurrRoomNum(){
		return m_mapRoom.size();
	}
	private void startHeartCheckTask(){
		class DealRoomTask extends TimerTask{
			@Override
			public void run() {
				long currTime = System.currentTimeMillis();
				Iterator<Map.Entry<Integer, GameAgent>> itGamer = GameAgent.agents.entrySet().iterator();
				while (itGamer.hasNext()) {
					Map.Entry<Integer, GameAgent> agents = itGamer.next();
					if(agents != null){
						GameAgent agent = agents.getValue();
						SHMUser value = agent.user;
						if (value != null && value.getHeartTime() != 0 && Math.abs(value.getHeartTime() - currTime) >= 5000 && m_mapUserRoom.containsKey(value.m_lUid)) {
							value.setHeartTime(0);
							JSONObject json = new JSONObject();
							IRoom room = m_mapUserRoom.get(value.getUid());
							String gameType = room.GetType();
							if(gameType.equals("DDZ")){
								json.put("command","ddzmsg");
							}else if(gameType.equals("PDK")){
								json.put("command","pdkmsg");
							}else if(gameType.equals("NTPDK")){
								json.put("command","ntpdkmsg");
							}else if(gameType.equals("CP")){
								json.put("command","cpmsg");
							}else if(gameType.equals("SJ")){
								json.put("command","sjmsg");
							}else if(gameType.equals("BJ") || gameType.equals("LABJ")){
								json.put("command", "bjzmsg");
							}else if(gameType.equals("TTZ")){
								json.put("command","ttzmsg");
							}else if(gameType.equals("NIUNIU")){
								json.put("command", "niuniumsg");
							}else if(gameType.equals("NIUNIU10")){
								json.put("command", "niuniumsg10");
							}else if(gameType.equals("HNNIUNIU")){
								json.put("command", "hnniuniumsg");
							}else if(gameType.equals("SSZLIU")){
								json.put("command", "sszliumsg");
							}else if(gameType.equals("SSZ")){
								json.put("command", "sszmsg");
							}else if(gameType.equals("FJSSZ")){
								json.put("command", "fjsszmsg");
							}else if(gameType.equals("DGT")){
								json.put("command","dgtmsg");
							}else if(gameType.equals("ZJH")){
								json.put("command","zjhmsg");
							}else if(gameType.equals("ZJH10")){
								json.put("command","zjhmsg10");
							}else if(gameType.equals("JDSGJ")){
								json.put("command","sgjmsg");
							}else{
								json.put("command","mjmsg");
							}
							json.put("v", 1);
							json.put("uid",value.m_lUid);
							json.put("data","inBack|0");
							if(agent != null){
								dthall.getInstance().OnRecv(agent, json);
							}
						}
					}
				}
			}
		}
		Timer timer = new Timer();
		DealRoomTask task = new DealRoomTask();
		timer.schedule(task,5000,5000);
	}
	//检测超时没有准备的房间，4分钟之内没有开始的普通房间，直接关闭,没有开始并且只有一个人
	public void startNoUseRoomCheck(){
		class DealRoomTask extends TimerTask{
			@Override
			public void run() {
				Handle_OnCheckOverTimeRoom();
			}
		}
		Timer timer = new Timer();
		DealRoomTask task = new DealRoomTask();
		timer.schedule(task,1000 * 60 * 2,1000 * 60 * 2);
	}
	//检测房间的创建销毁信息，发现不符合规则的立马删除
	public void startCheckRoomZooInfo(){
		class CheckRoomZooTask extends TimerTask{
			@Override
			public void run() {
				CommonZooListener.getInstance().checkRoomCreatedInfo(NodeInfoVo.getKey(GlobalSetting.getInstance().getSelfNodeInfo()));
			}
		}
		Timer timer = new Timer();
		CheckRoomZooTask task = new CheckRoomZooTask();
		timer.schedule(task,1000 * 30,1000 * 30);	
	}
	//检测系统的繁忙程度，如果被卡或者被攻击，连续5分钟报警，这里呼叫login启动备选服务器
	public void startCheckSystemBusy(){
		class SystemCheck extends TimerTask{
			public int memError = 0;
			public int cpuError = 0;
			public Timer timer;
			@Override
			public void run() {
				try {
					SystemInfo info = GlobalRoutine.readSystemInfo();
					if(info.m_memInfo > 0.8){
						memError++;
					}else{
						memError = 0;
					}
					if(info.m_cpuInfo > 80.0){
						cpuError++;
					}else{
						cpuError = 0;
					}
					if(memError >= 10 || cpuError >= 10){
						if(memError >= 10){
							System.out.println("mem超负荷+" + NodeInfoVo.getKey(GlobalSetting.getInstance().getSelfNodeInfo()));
						}
						if(cpuError >= 10){
							System.out.println("cpu超负荷" + NodeInfoVo.getKey(GlobalSetting.getInstance().getSelfNodeInfo()));
						}
						//开始报警
						if(GlobalSetting.getInstance().getSelfNodeInfo().nodeType == NodeType.GATE){
							net.sf.json.JSONObject pub = new net.sf.json.JSONObject();
							pub.put("command","pub_notify_login_gate_need_more");
							AdminRedis.getInstance().pubAdminSubMsg(pub);
						}else{
							net.sf.json.JSONObject pub = new net.sf.json.JSONObject();
							pub.put("command","pub_notify_login_logic_need_more");
							AdminRedis.getInstance().pubAdminSubMsg(pub);
						}
						this.timer.cancel();
					}
				} catch (SigarException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (Exception e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				MonitorInfoBean infoBean = SystemInfoTools.getMonitorInfoBean();
				double cpuRate = infoBean.getCpuUsage();

				if(GlobalSetting.getInstance().getSelfNodeInfo().nodeType == NodeType.GATE){
					System.out.println("我是网关本进程cpu占用率:" + cpuRate);
				}else{
					System.out.println("我是逻辑本进程cpu占用率:" + cpuRate);
				}
				if(cpuRate >= m_gateCpuRateThreadHold && GlobalSetting.getInstance().getSelfNodeInfo().nodeType == NodeType.GATE){
					//gate cpu占用过高，应该被攻击或者打爆了，准备重启
					String nodeInfo = NodeInfoVo.getKey(GlobalSetting.getInstance().getSelfNodeInfo());
					System.out.println("网关信息:" + nodeInfo + " cpu_threshold=" + m_gateCpuRateThreadHold);
					CHttpClient c = new CHttpClient();
					c.unregisterGateInfo(nodeInfo);
					class ShutDownTask extends TimerTask{
						@Override
						public void run() {
							System.exit(0);
						}
					}
					Timer timer = new Timer();
					timer.schedule(new ShutDownTask(),2000);
				}
			}
		}
		Timer timer = new Timer();
		SystemCheck task = new SystemCheck();
		task.timer = timer;
		timer.schedule(task,1000 * 60,1000 * 60);
	}
	public void Handle_OnCheckOverTimeRoom(){
		int curTime = (int)(System.currentTimeMillis() / 1000);
		try{
			Iterator<Map.Entry<Integer, IRoom>> itRoom = m_mapRoom.entrySet().iterator();
			while (itRoom.hasNext()) {
				Map.Entry<Integer, IRoom> entry = itRoom.next();
				IRoom value = entry.getValue();
				int dealTime = value.getDealTime();
				int createTime = value.getCreateTime();
				//4分钟没有开始，并且房间内只有一个人
				if((curTime - createTime >= 60 * 4) && dealTime == 0 && value.getPlayerCount() == 1){
					itRoom.remove();
					NotifyRemoveUserRoom(value);
					if(value.getClubId() != 0){
						ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomDismiss(value.getClubId(), value.GetID());
					}
					
					if(value.GetID() != 0)
						LogicServer.getInstance().afterDestoryRoom(String.valueOf(value.GetCreator()),value.GetID(),value.getStatus());
				}else if((curTime - createTime >= 60 * 60 * 24)){
					//超过24个小时的房间直接关闭
					itRoom.remove();
					NotifyRemoveUserRoom(value);
					if(value.getClubId() != 0){
						ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomDismiss(value.getClubId(), value.GetID());
					}
					
					if(value.GetID() != 0)
						LogicServer.getInstance().afterDestoryRoom(String.valueOf(value.GetCreator()),value.GetID(),value.getStatus());
				}
			}
		}catch(Exception e){
			
		}
	}
	
	public IRoom Handle_OnCreateClubNullRoom(JSONObject root){
		String room_type = root.optString("room_type");
		String room_param = root.optString("room_param");
		IRoom tbl = null;
		boolean isFangGuan = false;
		int _Uid = 0;
		if ("HZMJ".equals(room_type)) {
			tbl = Server.Hnmj.HZMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("CBDD".equals(room_type)){
			tbl = Server.Hbmj.CBDDMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if("XXMJ".equals(room_type)){
			tbl = Server.Hnmj.XXMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if("ZZMJ".equals(room_type)){
			tbl = Server.Hnmj.ZZMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("ZJH".equals(room_type)) {
			tbl = Server.Poker.ZJH.ZjhTableMgr.CreateTable(_Uid, room_param, isFangGuan); 
		} else if ("ZJH10".equals(room_type)) {
			tbl = Server.Poker.ZJH10.ZjhTable10Mgr.CreateTable(_Uid, room_param, isFangGuan); 
		} else if ("NIUNIU".equals(room_type)) {
			tbl = Server.Poker.NiuNiu.niuniuTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		} else if ("NIUNIU10".equals(room_type)) {
			tbl = Server.Poker.NiuNiu10.niuniuTable10Mgr.CreateTable(_Uid, room_param, isFangGuan);
		} else if("HNNIUNIU".equals(room_type)){
			tbl = Server.Poker.HnNiuNiu.niuniuTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("FJSSZ".equals(room_type)) {
			tbl = Server.Poker.FJSSZ.SSZTableMgr.CreateTable(_Uid,room_param,isFangGuan); 
		}else if ("SSZLIU".equals(room_type)) {
			tbl = Server.Poker.SSZLIU.SSZTableMgr.CreateTable(_Uid,room_param,isFangGuan); 
		}else if ("DDZ".equals(room_type)) {
			tbl = Server.Poker.DDZ.DDZTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("PDK".equals(room_type)) {
			tbl = Server.Poker.PDK.PDKTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("NTPDK".equals(room_type)) {
			tbl = Server.Poker.NTPDK.PDKTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("CP".equals(room_type)) {
			tbl = Server.Jsmj.RGCP.RGCPTableMgr.instance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("HQMJ".equals(room_type)) {
			tbl = Server.AHMJ.HQMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFHZ".equals(room_type)) {
			tbl = Server.AHMJ.HFHZ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFMJ".equals(room_type)) {
			tbl = Server.AHMJ.HFMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFSR".equals(room_type)) {
			tbl = Server.AHMJ.HFSR.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LAMJ".equals(room_type)) {
			tbl = Server.AHMJ.LAMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LAHZ".equals(room_type)) {
			tbl = Server.AHMJ.LAHZ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("SCMJ".equals(room_type)) {
			tbl = Server.AHMJ.SCMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("SCDB".equals(room_type)) {
			tbl = Server.AHMJ.SCDB.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if(room_type.equals("TTZ")){
			tbl = Server.Poker.TTZ.TTZTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("BJ".equals(room_type)) {
			tbl = Server.Poker.BJZ.BJZTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LABJ".equals(room_type)){
			tbl = Server.Poker.LABJZ.BJZTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("JZMJ".equals(room_type)) {
			tbl = Server.AHMJ.JZMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("YJMJ".equals(room_type)) {
			tbl = Server.AHMJ.YJMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("HSMJ".equals(room_type)){
			tbl = Server.AHMJ.HSMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("MDMJ".equals(room_type)){
			tbl = Server.AHMJ.MDMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("DGT".equals(room_type)){
			tbl = Server.Poker.DGT.DGTTableMgr.getInstance().CreateTable(_Uid,room_param,false);
		}else if("FKSGJ".equals(room_type)){
			tbl = Server.Dwc.fksgj.fksgjTableMgr.CreateTable(_Uid, room_param, false);
		}else if("BRSGJ".equals(room_type)){
			tbl = Server.Dwc.brsgj.brsgjTableMgr.CreateTable(_Uid, room_param, false);
		}else if("FKFISH".equals(room_type)){
			tbl = Server.Dwc.fkfish.FkFishTableMgr.CreateTable(_Uid, room_param, false);
		}else if("SHZ".equals(room_type)){
			tbl = Server.Dwc.shz.shzTableMgr.CreateTable(_Uid, room_param, false);
		}else if("SLHB".equals(room_type)){
			tbl = Server.Dwc.slhb.SlhbTableMgr.CreateTable(_Uid, room_param, false);
		}else if("CQSSC".equals(room_type)){
			tbl = Server.Dwc.cqssc.CqsscTableMgr.CreateTable(_Uid, room_param, false);
		}else if(("PK10".equals(room_type))){
			tbl = Server.Dwc.pk10.pk10TableMgr.CreateTable(_Uid, room_param, false);
		}else if(("AZXY5".equals(room_type))){
			tbl = Server.Dwc.azxy5.Azxy5TableMgr.CreateTable(_Uid, room_param, false);
		}
		if(tbl != null){
			LogicServer.getInstance().afterCreateRoom(String.valueOf(0),tbl.GetID(),tbl.getStatus(), tbl.GetType());
		}
		return tbl;
	}
	/**
	 * 创建俱乐部游戏房间
	 * @param agent
	 * @param root
	 */
	public IRoom Handle_OnCreateClubRoom(GameAgent agent,JSONObject root){
		LogicServer.getInstance().pushUserToOtherServer();
		
		String room_type = root.optString("room_type");
		String room_param = root.optString("room_param");
		int _Uid = agent.getUid();

		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		int user_gem = user.getGem(0);
		int max_cost_gem = 0;
		//添加金币，精力等各种判断

		IRoom tbl = null;
		boolean isFangGuan = false;
		if ("HZMJ".equals(room_type)) {
			tbl = Server.Hnmj.HZMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("CBDD".equals(room_type)){
			tbl = Server.Hbmj.CBDDMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if("XXMJ".equals(room_type)){
			tbl = Server.Hnmj.XXMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if("ZZMJ".equals(room_type)){
			tbl = Server.Hnmj.ZZMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("ZJH".equals(room_type)) {
			tbl = Server.Poker.ZJH.ZjhTableMgr.CreateTable(_Uid, room_param, isFangGuan); 
		} else if ("ZJH10".equals(room_type)) {
			tbl = Server.Poker.ZJH10.ZjhTable10Mgr.CreateTable(_Uid, room_param, isFangGuan); 
		} else if ("NIUNIU".equals(room_type)) {
			tbl = Server.Poker.NiuNiu.niuniuTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}  else if ("NIUNIU10".equals(room_type)) {
			tbl = Server.Poker.NiuNiu10.niuniuTable10Mgr.CreateTable(_Uid, room_param, isFangGuan);
		} else if ("HNNIUNIU".equals(room_type)){
			tbl = Server.Poker.HnNiuNiu.niuniuTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("FJSSZ".equals(room_type)) {
			tbl = Server.Poker.FJSSZ.SSZTableMgr.CreateTable(_Uid,room_param,isFangGuan); 
		}else if ("SSZLIU".equals(room_type)) {
			tbl = Server.Poker.SSZLIU.SSZTableMgr.CreateTable(_Uid,room_param,isFangGuan); 
		}else if ("DDZ".equals(room_type)) {
			tbl = Server.Poker.DDZ.DDZTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("PDK".equals(room_type)) {
			tbl = Server.Poker.PDK.PDKTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("NTPDK".equals(room_type)) {
			tbl = Server.Poker.NTPDK.PDKTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if("CP".equals(room_type)){
			tbl = Server.Jsmj.RGCP.RGCPTableMgr.instance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("HQMJ".equals(room_type)) {
			tbl = Server.AHMJ.HQMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFHZ".equals(room_type)) {
			tbl = Server.AHMJ.HFHZ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFMJ".equals(room_type)) {
			tbl = Server.AHMJ.HFMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFSR".equals(room_type)) {
			tbl = Server.AHMJ.HFSR.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LAMJ".equals(room_type)) {
			tbl = Server.AHMJ.LAMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LAHZ".equals(room_type)) {
			tbl = Server.AHMJ.LAHZ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("SCMJ".equals(room_type)) {
			tbl = Server.AHMJ.SCMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("SCDB".equals(room_type)) {
			tbl = Server.AHMJ.SCDB.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if(room_type.equals("TTZ")){
			tbl = Server.Poker.TTZ.TTZTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("BJ".equals(room_type)) {
			tbl = Server.Poker.BJZ.BJZTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LABJ".equals(room_type)){
			tbl = Server.Poker.LABJZ.BJZTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("JZMJ".equals(room_type)) {
			tbl = Server.AHMJ.JZMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("YJMJ".equals(room_type)) {
			tbl = Server.AHMJ.YJMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("HSMJ".equals(room_type)){
			tbl = Server.AHMJ.HSMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("MDMJ".equals(room_type)){
			tbl = Server.AHMJ.MDMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("DGT".equals(room_type)){
			tbl = Server.Poker.DGT.DGTTableMgr.getInstance().CreateTable(_Uid,room_param,false);
		}else if("FKSGJ".equals(room_type)){
			tbl = Server.Dwc.fksgj.fksgjTableMgr.CreateTable(_Uid, room_param,false);
		}else if("BRSGJ".equals(room_type)){
			tbl = Server.Dwc.brsgj.brsgjTableMgr.CreateTable(_Uid, room_param, false);
		}else if("FKFISH".equals(room_type)){
			tbl = Server.Dwc.fkfish.FkFishTableMgr.CreateTable(_Uid, room_param, false);
		}else if("SHZ".equals(room_type)){
			tbl = Server.Dwc.shz.shzTableMgr.CreateTable(_Uid, room_param, false);
		}else if("SLHB".equals(room_type)){
			tbl = Server.Dwc.slhb.SlhbTableMgr.CreateTable(_Uid, room_param, false);
		}else if("CQSSC".equals(room_type)){
			tbl = Server.Dwc.cqssc.CqsscTableMgr.CreateTable(_Uid, room_param, false);
		}else if(("PK10".equals(room_type))){
			tbl = Server.Dwc.pk10.pk10TableMgr.CreateTable(_Uid, room_param, false);
		}else if(("AZXY5".equals(room_type))){
			tbl = Server.Dwc.azxy5.Azxy5TableMgr.CreateTable(_Uid, room_param, false);
		}
		

		if (tbl != null) {
			LogicServer.getInstance().afterCreateRoom(String.valueOf(user.getUid()),tbl.GetID(),tbl.getStatus(), tbl.GetType());
			int result = tbl.CanSit(_Uid);
			Integer room_id = tbl.GetID();
			if(tbl.getPayway().equals("AAPAY") && tbl.getCostGem()>user.getGem(0)){
				CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
				cmd.uid = _Uid;
				cmd.cbResult = 11;
				cmd.room_type = "";
				cmd.room_id = room_id;

				String sData = cmd.getJsonData();
				agent.SendMessage(sData);
				return null;
			}else{
				if (result < 10) {
					{
						CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
						cmd.uid = _Uid;
						cmd.cbResult = 0;
						cmd.room_type = room_type;
						cmd.room_id = room_id;

						String sData = cmd.getJsonData();
						agent.SendMessage(sData);
						
						//lock user with room
						LogicServer.getInstance().lockUserWithRoom(agent,cmd.room_id);
					}

					tbl.OnUserSit(_Uid);
					m_mapUserRoom.put(_Uid, tbl);
					return tbl;
				} else {
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = result;
					cmd.room_type = "";
					cmd.room_id = room_id;

					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
				}
			}
		} else {
			CMD_S_CreateRoom cmd = new CMD_S_CreateRoom();
			cmd.uid = _Uid;
			cmd.cbResult = 1;
			String sData = cmd.getJsonData();

			dthall.getInstance().onSend(_Uid, sData);
		}
		return tbl;
	}
	/**
	 * 加入俱乐部游戏房间
	 * @param agent
	 * @param root
	 */
	public IRoom HandleOn_JoinClubRoom(GameAgent agent,JSONObject root){
		//先判断是否在房间内
//		String lockInfo = DbInfoMgr.getInstance().getUserRoomLockInfo(String.valueOf(agent.getUid()));
//		if(lockInfo != null){
//			LogicRoomLockInfo roomInfo = JsonUtils.deserialize(lockInfo, LogicRoomLockInfo.class);
//			if(m_mapRoom.containsKey(roomInfo._roomId)){
//				//直接加入
//				IRoom room = m_mapRoom.get(roomInfo._roomId);
//				int seat = room.FindSeat(agent.getUid());
//				if(seat != Constants.INVALID_CHAIR){
//					//有效直接进入此房间
//					root.put("room_id", roomInfo._roomId);
//					root.put("hasTry", true);
//					Handle_OnJoinRoom(agent,root);
//					
//					OtherRoom otherroom = new OtherRoom();
//					return otherroom;
//				}else{
//					//无效
//					DbInfoMgr.getInstance().removeUserRoomLockInfo(String.valueOf(agent.getUid()));
//				}
//			}else{
//				//无效
//				DbInfoMgr.getInstance().removeUserRoomLockInfo(String.valueOf(agent.getUid()));	
//				//发布通知，把此用户从那个房间移出去
//				JSONObject pub = new JSONObject();
//				pub.put("command",AdminEnum.PUB_REQ_REMOVE_USER_FROM_ROOM);
//				pub.put("value1",roomInfo._roomId);
//				pub.put("value2",agent.getUID());
//				AdminRedis.getInstance().pubAdminSubMsg(pub);
//			}
//		}
		
		Integer room_id = root.optInt("room_id");
		Integer _Uid = agent.getUid();
		IRoom tbl = m_mapRoom.get(room_id);
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		//add,zws
		if(user != null && tbl == null && user != null && root.has("hasTry") == false && NodePeerMgr.getInstance().hasSuchCreatedRoomInfo(room_id)){
			LogicServer logic = LogicServer.getInstance();
			logic.canNotFindRoom(LogicServer.getUserAccount(agent),user.m_sAccount,room_id, root.toString(),agent.getAgentChannelHandlerContext());
			OtherRoom otherroom = new OtherRoom();
			return otherroom;
		}
		//add end
		if (tbl != null && user != null) {
			String payway = tbl.getPayway();
			if(payway.equals("CLUBPAY")){
				if(!ClubMgr.getInstance().m_clubHandler.checkClubOwnerDia(tbl.getClubId(),100)){
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = 20;
					cmd.room_type = "";
					cmd.room_id = room_id;

					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
					return null;
				}
			}			
			int result = tbl.CanSit(_Uid);
			if(tbl.getPayway().equals("AAPAY") && tbl.getCostGem()>user.getGem(0)){
				CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
				cmd.uid = _Uid;
				cmd.cbResult = 11;
				cmd.room_type = "";
				cmd.room_id = room_id;

				String sData = cmd.getJsonData();
				agent.SendMessage(sData);
				return null;
			}else{
				String room_type = tbl.GetType();
				if (result < 10) {
					{
						CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
						cmd.uid = _Uid;
						cmd.cbResult = 0;
						cmd.room_type = room_type;
						cmd.room_id = room_id;

						String sData = cmd.getJsonData();
						agent.SendMessage(sData);
						
						//lock user with room
						LogicServer.getInstance().lockUserWithRoom(agent,cmd.room_id);
					}

					tbl.OnUserSit(_Uid);
					m_mapUserRoom.put(_Uid, tbl);
					return tbl;
				} else {
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = result;
					cmd.room_type = "";
					cmd.room_id = room_id;

					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
				}
			}
		} else {
			CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
			cmd.uid = _Uid;
			cmd.cbResult = 1;
			cmd.room_type = "";
			cmd.room_id = room_id;

			String sData = cmd.getJsonData();
			agent.SendMessage(sData);
		}
		return null;
	}
	/**
	 * 创建游戏房间
	 * @param agent
	 * @param root
	 */
	public void Handle_OnCreateRoom(GameAgent agent, JSONObject root) {
		//先判断是否在房间内
//		String lockInfo = DbInfoMgr.getInstance().getUserRoomLockInfo(String.valueOf(agent.getUid()));
//		if(lockInfo != null){
//			LogicRoomLockInfo roomInfo = JsonUtils.deserialize(lockInfo, LogicRoomLockInfo.class);
//			if(m_mapRoom.containsKey(roomInfo._roomId)){
//				//直接加入
//				IRoom room = m_mapRoom.get(roomInfo._roomId);
//				int seat = room.FindSeat(agent.getUid());
//				if(seat != Constants.INVALID_CHAIR){
//					//有效直接进入此房间
//					root.put("room_id", roomInfo._roomId);
//					root.put("hasTry", true);
//					Handle_OnJoinRoom(agent,root);
//					return;
//				}else{
//					//无效
//					DbInfoMgr.getInstance().removeUserRoomLockInfo(String.valueOf(agent.getUid()));
//				}
//			}else{
//				//无效
//				DbInfoMgr.getInstance().removeUserRoomLockInfo(String.valueOf(agent.getUid()));	
//				//发布通知，把此用户从那个房间移出去
//				JSONObject pub = new JSONObject();
//				pub.put("command",AdminEnum.PUB_REQ_REMOVE_USER_FROM_ROOM);
//				pub.put("value1",roomInfo._roomId);
//				pub.put("value2",agent.getUID());
//				AdminRedis.getInstance().pubAdminSubMsg(pub);
//			}
//		}
		LogicServer.getInstance().pushUserToOtherServer();
		
		String room_type = root.optString("room_type");
		String room_param = root.optString("room_param");
		
		int _Uid = agent.getUid();

		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user == null)
		{
			return;
		}
		int user_gem = user.getGem(0);
		int max_cost_gem = 0;


		IRoom tbl = null;
		boolean isFangGuan = false;
		if ("HZMJ".equals(room_type)) {
			tbl = Server.Hnmj.HZMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("CBDD".equals(room_type)){
			tbl = Server.Hbmj.CBDDMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if("XXMJ".equals(room_type)){
			tbl = Server.Hnmj.XXMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if("ZZMJ".equals(room_type)){
			tbl = Server.Hnmj.ZZMJ.MajTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("ZJH".equals(room_type)) {
			tbl = Server.Poker.ZJH.ZjhTableMgr.CreateTable(_Uid, room_param, isFangGuan); 
		} else if ("ZJH10".equals(room_type)) {
			tbl = Server.Poker.ZJH10.ZjhTable10Mgr.CreateTable(_Uid, room_param, isFangGuan); 
		}  else if ("NIUNIU".equals(room_type)) {
			tbl = Server.Poker.NiuNiu.niuniuTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}  else if ("NIUNIU10".equals(room_type)) {
			tbl = Server.Poker.NiuNiu10.niuniuTable10Mgr.CreateTable(_Uid, room_param, isFangGuan);
		} else if ("HNNIUNIU".equals(room_type)){
			tbl = Server.Poker.HnNiuNiu.niuniuTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("FJSSZ".equals(room_type)) {
			tbl = Server.Poker.FJSSZ.SSZTableMgr.CreateTable(_Uid,room_param,isFangGuan); 
		}else if ("SSZLIU".equals(room_type)) {
			tbl = Server.Poker.SSZLIU.SSZTableMgr.CreateTable(_Uid,room_param,isFangGuan); 
		}else if ("DDZ".equals(room_type)) {
			tbl = Server.Poker.DDZ.DDZTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("PDK".equals(room_type)) {
			tbl = Server.Poker.PDK.PDKTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("NTPDK".equals(room_type)) {
			tbl = Server.Poker.NTPDK.PDKTableMgr.getInstance().CreateTable(_Uid, room_param, isFangGuan);
		}else if("CP".equals(room_type)){
			tbl = Server.Jsmj.RGCP.RGCPTableMgr.instance().CreateTable(_Uid, room_param, isFangGuan);
		}else if ("HQMJ".equals(room_type)) {
			tbl = Server.AHMJ.HQMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFHZ".equals(room_type)) {
			tbl = Server.AHMJ.HFHZ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFMJ".equals(room_type)) {
			tbl = Server.AHMJ.HFMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("HFSR".equals(room_type)) {
			tbl = Server.AHMJ.HFSR.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LAMJ".equals(room_type)) {
			tbl = Server.AHMJ.LAMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LAHZ".equals(room_type)) {
			tbl = Server.AHMJ.LAHZ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("SCMJ".equals(room_type)) {
			tbl = Server.AHMJ.SCMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("SCDB".equals(room_type)) {
			tbl = Server.AHMJ.SCDB.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if(room_type.equals("TTZ")){
			tbl = Server.Poker.TTZ.TTZTableMgr.CreateTable(_Uid, room_param, isFangGuan);
		}else if ("BJ".equals(room_type)) {
			tbl = Server.Poker.BJZ.BJZTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("LABJ".equals(room_type)){
			tbl = Server.Poker.LABJZ.BJZTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("JZMJ".equals(room_type)){
			tbl = Server.AHMJ.JZMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if ("YJMJ".equals(room_type)){
			tbl = Server.AHMJ.YJMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("HSMJ".equals(room_type)){
			tbl = Server.AHMJ.HSMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("MDMJ".equals(room_type)){
			tbl = Server.AHMJ.MDMJ.MajTableMgr.CreateTable(_Uid, room_param, false);
		}else if("DGT".equals(room_type)){
			tbl = Server.Poker.DGT.DGTTableMgr.getInstance().CreateTable(_Uid,room_param,false);
		}else if("FKSGJ".equals(room_type)){
			tbl = Server.Dwc.fksgj.fksgjTableMgr.CreateTable(_Uid,room_param,false);
		}else if("BRSGJ".equals(room_type)){
			tbl = Server.Dwc.brsgj.brsgjTableMgr.CreateTable(_Uid, room_param, false);
		}else if("FKFISH".equals(room_type)){
			tbl = Server.Dwc.fkfish.FkFishTableMgr.CreateTable(_Uid, room_param, false);
		}else if("SHZ".equals(room_type)){
			tbl = Server.Dwc.shz.shzTableMgr.CreateTable(_Uid, room_param, false);
		}else if("SLHB".equals(room_type)){
			tbl = Server.Dwc.slhb.SlhbTableMgr.CreateTable(_Uid, room_param, false);
		}else if("CQSSC".equals(room_type)){
			tbl = Server.Dwc.cqssc.CqsscTableMgr.CreateTable(_Uid, room_param, false);
		}else if(("PK10".equals(room_type))){
			tbl = Server.Dwc.pk10.pk10TableMgr.CreateTable(_Uid, room_param, false);
		}else if(("AZXY5".equals(room_type))){
			tbl = Server.Dwc.azxy5.Azxy5TableMgr.CreateTable(_Uid, room_param, false);
		}
		

		if (tbl != null) {
			LogicServer.getInstance().afterCreateRoom(user.m_sAccount,tbl.GetID(),tbl.getStatus(), tbl.GetType());
			{
				CMD_S_CreateRoom cmd = new CMD_S_CreateRoom();
				cmd.uid = _Uid;
				cmd.cbResult = 0;

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(_Uid, sData);
			}

			{
				CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
				cmd.uid = _Uid;
				cmd.cbResult = 0;
				cmd.room_type = room_type;
				cmd.room_id = tbl.GetID();

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(_Uid, sData);
				//lock user with room
				LogicServer.getInstance().lockUserWithRoom(agent,cmd.room_id);
			}

			tbl.OnUserSit(_Uid);
			OnCreateRoom(_Uid, (IRoom) tbl);
			
		} else {
			CMD_S_CreateRoom cmd = new CMD_S_CreateRoom();
			cmd.uid = _Uid;
			cmd.cbResult = 1;
			String sData = cmd.getJsonData();

			dthall.getInstance().onSend(_Uid, sData);
		}
	}

	void OnCreateRoom(int _Uid, IRoom pIRoom) {
		m_mapUserRoom.put(_Uid, pIRoom);
		m_mapRoom.put(pIRoom.GetID(), pIRoom);
	}

	public void Handle_OnReturnRoom(GameAgent agent, JSONObject root) {
		Integer _Uid = agent.getUid();
		IRoom iterUser = m_mapUserRoom.get(_Uid);
		if (iterUser != null) {
			IRoom tbl = iterUser;
			String room_type = tbl.GetType();
			int room_id = iterUser.GetID();

			IRoom iter = m_mapRoom.get(room_id);
			if (iterUser.equals(iter)) {
				tbl = iter;
				int ret = tbl.CanSit(_Uid);
				if (ret >= 0) {
					{
						CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
						cmd.uid = _Uid;
						cmd.cbResult = 0;
						cmd.room_type = tbl.GetType();
						cmd.room_id = room_id;

						String sData = cmd.getJsonData();
						agent.SendMessage(sData);
						//lock user with room
						LogicServer.getInstance().lockUserWithRoom(agent,cmd.room_id);
					}

					tbl.OnUserSit(_Uid);
					m_mapUserRoom.put(_Uid, tbl);
				} else {
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = ret;
					cmd.room_type = "";
					cmd.room_id = room_id;

					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
				}
			} else {
				CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
				cmd.uid = _Uid;
				cmd.cbResult = 3;
				cmd.room_type = "";
				cmd.room_id = room_id;

				String sData = cmd.getJsonData();
				agent.SendMessage(sData);
			}
		}
	}

	public void Handle_OnDismissRoom(GameAgent agent, JSONObject root) {
		Integer room_id = root.getInt("room_id");
		Integer _Uid = agent.getUid();
		IRoom tbl = m_mapRoom.get(room_id);
		if (tbl != null && tbl.getPlayerCount() == 0) {
			OnDismissRoom(tbl);
			m_mapFZ.remove(tbl.GetID());

			CMD_S_DissmissRoom cmd = new CMD_S_DissmissRoom();
			cmd.uid = _Uid;
			cmd.cbResult = 0;
			cmd.room_id = room_id;

			String sData = cmd.getJsonData();
			agent.SendMessage(sData);

		}
		onDealFangGuanGetRoomList(agent);
	}
	//added,can not find this room anywhere
	public void Handle_OnJoinRoomNoFound(GameAgent agent,JSONObject root){
		Integer room_id = root.optInt("room_id");
		Integer _Uid = agent.getUid();

		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		if(user != null){
			CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
			cmd.uid = _Uid;
			cmd.cbResult = 1;
			cmd.room_type = "";
			cmd.room_id = room_id;
	
			String sData = cmd.getJsonData();
			agent.SendMessage(sData);
		}
		if(root.containsKey("club_id")){
			//发布消息
			int clubid = root.optInt("club_id");
			ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomDismiss(clubid, room_id);
		}
	}
	public void Handle_OnJoinRoom(GameAgent agent, JSONObject root) {
		Integer room_id = root.optInt("room_id");
		Integer _Uid = agent.getUid();
		IRoom tbl = m_mapRoom.get(room_id);
		SHMUser user = dthall.getInstance().getUserInfo(_Uid);
		//add,zws
		if(tbl == null && user != null && root.has("hasTry") == false && NodePeerMgr.getInstance().hasSuchCreatedRoomInfo(room_id)){
			LogicServer logic = LogicServer.getInstance();
			logic.canNotFindRoom(LogicServer.getUserAccount(agent),user.m_sAccount,room_id, root.toString(),agent.getAgentChannelHandlerContext());
			return;
		}
		//add end
		if (tbl != null && user != null) {
			//此处无法加入俱乐部房间
			int result = tbl.CanSit(_Uid);
			if(result < 10 && tbl.getClubId() != 0){//暂时不让加入俱乐部房间
				//判断俱乐部
				if(ClubRedis.getInstance().isMyOwnClub(_Uid, tbl.getClubId()) || ClubRedis.getInstance().isInSuchClub(tbl.getClubId(), _Uid)){
					String payway = tbl.getPayway();
					if(payway.equals("CLUBPAY")){
						if(!ClubMgr.getInstance().m_clubHandler.checkClubOwnerDia(tbl.getClubId(),100)){
							CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
							cmd.uid = _Uid;
							cmd.cbResult = 20;
							cmd.room_type = "";
							cmd.room_id = room_id;

							String sData = cmd.getJsonData();
							agent.SendMessage(sData);
							return;
						}
					}
					String room_type = tbl.GetType();
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = 0;
					cmd.room_type = room_type;
					cmd.room_id = room_id;

					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
					
					//lock user with room
					LogicServer.getInstance().lockUserWithRoom(agent,cmd.room_id);

					tbl.OnUserSit(_Uid);
					m_mapUserRoom.put(_Uid, tbl);
					ClubMgr.getInstance().m_clubHandler.handleOn_UserJoinClubRoom(user.getNickName(null),tbl,tbl.getClubId(),_Uid,room_id);
					return;
				}else{			
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = -1;
					cmd.room_type = "" + tbl.getClubId();
					cmd.room_id = room_id;
	
					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
					return;
				}
			}
			if(tbl.getPayway().equals("AAPAY") && tbl.getCostGem()>user.getGem(0)){
				CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
				cmd.uid = _Uid;
				cmd.cbResult = 11;
				cmd.room_type = "";
				cmd.room_id = room_id;

				String sData = cmd.getJsonData();
				agent.SendMessage(sData);
			}else{
				String room_type = tbl.GetType();
				if (result < 10) {
					{
						CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
						cmd.uid = _Uid;
						cmd.cbResult = 0;
						cmd.room_type = room_type;
						cmd.room_id = room_id;

						String sData = cmd.getJsonData();
						agent.SendMessage(sData);
						//lock user with room
						LogicServer.getInstance().lockUserWithRoom(agent,cmd.room_id);
					}

					tbl.OnUserSit(_Uid);
					m_mapUserRoom.put(_Uid, tbl);
				} else {
					CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
					cmd.uid = _Uid;
					cmd.cbResult = result;
					cmd.room_type = "";
					cmd.room_id = room_id;

					String sData = cmd.getJsonData();
					agent.SendMessage(sData);
				}
			}
		} else {
			CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
			cmd.uid = _Uid;
			cmd.cbResult = 1;
			cmd.room_type = "";
			cmd.room_id = room_id;

			String sData = cmd.getJsonData();
			agent.SendMessage(sData);
		}
	} 
	
	public void Handle_Res_Connection_JoinRoom(GameAgent agent,JSONObject root, Integer room_id) {
		Integer _Uid = agent.getUid();
		IRoom tbl = m_mapRoom.get(room_id);
		
		
		if (tbl != null) {
			String room_type = tbl.GetType();
			int result = tbl.CanSit(_Uid);
			if (result < 10) {
				tbl.OnUserSit(_Uid);
				m_mapUserRoom.put(_Uid, tbl);
				LogicServer.getInstance().lockUserWithRoom(agent, room_id);
			}
		} else {
//			CMD_S_JoinRoom cmd = new CMD_S_JoinRoom();
//			cmd.uid = _Uid;
//			cmd.cbResult = 1;
//			cmd.room_type = "";
//			cmd.room_id = room_id;
//			String sData = cmd.getJsonData();
//			agent.SendMessage(sData);
			JSONObject json = new JSONObject();
			json.put("command", root.optString("msgtype"));
			json.put(root.optString("msgtype"), "dismissroom|");
			agent.SendMessage(json.toString());
			LogicServer.getInstance().unlockUserWithRoom(agent, room_id);
		}
	}
	
	public void Handle_RequestDissmissRoom(int roomid){
		IRoom room = m_mapRoom.get(roomid);
		Iterator<Map.Entry<Integer, IRoom>> it = m_mapUserRoom.entrySet().iterator();
		while (it.hasNext()) {
			Map.Entry<Integer, IRoom> entry = it.next();
			IRoom value = entry.getValue();
			if (value.GetID() == roomid) {
				if(value.getClubId() != 0){
					int clubid = value.getClubId();
					ClubRedis.getInstance().delClubRoomInfo(clubid,roomid);
				}
				OnDismissRoom(value);
				it.remove(); // OK
			}
		}

		m_mapRoom.remove(room);
	}
	public void dismissAllUnStartedRoom(){
		Iterator<Map.Entry<Integer, IRoom>> it = m_mapRoom.entrySet().iterator();
		List<IRoom> rooms = new ArrayList<IRoom>();
		while (it.hasNext()) {
			Map.Entry<Integer, IRoom> entry = it.next();
			IRoom value = entry.getValue();
			if (value.getDealTime() == 0) {
				rooms.add(value);
			}
		}
		for(int i = 0;i < rooms.size();i++){
			IRoom value = rooms.get(i);
			//未开始
			OnKickOutRoom(value);
		}
	}
	public void Handle_OnUserRoom(GameAgent agent, JSONObject root) {
		try {
			Integer _Uid = agent.getUid();
			IRoom room = m_mapUserRoom.get(_Uid);
			CMD_S_UserRoom cmd = new CMD_S_UserRoom();

			int curTime = (int) (System.currentTimeMillis() / 1000);
			if (room != null) {
				int dealTime = (int) (System.currentTimeMillis() / 1000);
				try {
					dealTime = room.getCreateTime();
				} catch (Exception e) {
					e.printStackTrace();
				}

				if (curTime - dealTime > 3600 * 24) {
					Iterator<Map.Entry<Integer, IRoom>> it = m_mapUserRoom.entrySet().iterator();
					while (it.hasNext()) {
						Map.Entry<Integer, IRoom> entry = it.next();
						IRoom value = entry.getValue();
						if (value.GetID() == room.GetID()) {
							it.remove(); // OK
						}
					}

					m_mapRoom.remove(room);
				}
				int seat = room.FindSeat(_Uid);
				if (seat < 0) {
					if (m_mapUserRoom.containsKey(_Uid)) {
						m_mapUserRoom.remove(_Uid);
					}
				}
			}
			room = m_mapUserRoom.get(_Uid);
			if (room != null) {
				cmd.uid = _Uid;
				cmd.room_id = room.GetID();
			} else {
				cmd.uid = _Uid;
				cmd.room_id = 0;
			}

			String sData = cmd.getJsonData();
			agent.SendMessage(sData);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// 获取房管房间列表
	private void onDealFangGuanGetRoomList(GameAgent agent) {
		int lUid = agent.getUid();
		CMD_S_FGRoomList cmd = new CMD_S_FGRoomList();
		for (Integer roomId : m_mapFZ.keySet()) {
			IRoom room = m_mapFZ.get(roomId).get();
			if (room != null && room.GetCreator() == lUid) {
				if (cmd.AddRoomInfo(room.getRoomInfo()) == -1) {// 最多返回10个
					break;
				}
			}
		}
		agent.SendMessage(cmd.getJsonData());
	}
	public void OnDismissRoomByID(int id){
		if(!this.m_mapRoom.containsKey(id)){
			return;			
		}
		IRoom tbl = this.m_mapRoom.get(id);
		if (tbl == null)
			return;
		Integer creator = tbl.GetCreator();
		if (creator > 10) {
			SHMUser user = dthall.getInstance().getUserInfo(creator);
			if (user != null) {
				CMD_ChipInfo cmd = new CMD_ChipInfo();
				cmd.m_lUid = (long) creator;
				cmd.m_lTotalCoin = (long) user.getCoin(0);
				cmd.m_lTotalGem = (long) user.getGem(0);
				cmd.m_lTicket = 0L;

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(creator, sData);
			}
		}

		Iterator<Map.Entry<Integer, IRoom>> itUserRoom = m_mapUserRoom.entrySet().iterator();
		while (itUserRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itUserRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				System.out.println("delete this: " + key + " = " + key);
				itUserRoom.remove();
				SHMUser user = dthall.getInstance().getUserInfo(key);
				if(user != null){
					GameAgent agent = LogicServer.getUserAgent("" + user.getUid());
					if(agent == null){
						agent = LogicServer.getUserAgent("" + user.m_sAccount);
					}
					if(agent != null){
						LogicServer.getInstance().unlockUserWithRoom(agent,value.GetID());
						LogicServer.getInstance().afterQuitRoom(LogicServer.getUserAccount(agent));
						JSONObject json = new JSONObject();
						json.put("command","halldismissroom");
						agent.SendMessage(json.toString());
					}
				}
			}
		}

		Iterator<Map.Entry<Integer, IRoom>> itRoom = m_mapRoom.entrySet().iterator();
		while (itRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				System.out.println("delete this: " + key + " = " + key);
				itRoom.remove();

				if(value.GetID() != 0){
					LogicServer.getInstance().afterDestoryRoom(String.valueOf(value.GetCreator()),value.GetID(),value.getStatus());
					if(value.getClubId() != 0){
						//在俱乐部内
						ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomDismiss(value.getClubId(),value.GetID());
					}
				}
			}
		}
		m_mapFZ.remove(tbl.GetID());
	}
	public void OnKickOutRoom(IRoom tbl) {
		if (tbl == null)
			return;
		int roomid = tbl.GetID();
		Integer creator = tbl.GetCreator();
		if (creator > 10) {
			SHMUser user = dthall.getInstance().getUserInfo(creator);
			if (user != null) {
				CMD_ChipInfo cmd = new CMD_ChipInfo();
				cmd.m_lUid = (long) creator;
				cmd.m_lTotalCoin = (long) user.getCoin(0);
				cmd.m_lTotalGem = (long) user.getGem(0);
				cmd.m_lTicket = 0L;

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(creator, sData);
			}
		}

		Iterator<Map.Entry<Integer, IRoom>> itUserRoom = m_mapUserRoom.entrySet().iterator();
		while (itUserRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itUserRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				System.out.println("delete this: " + key + " = " + key);
				itUserRoom.remove();
				SHMUser user = dthall.getInstance().getUserInfo(key);
				if(user != null){
					GameAgent agent = LogicServer.getUserAgent("" + user.getUid());
					if(agent == null){
						agent = LogicServer.getUserAgent("" + user.m_sAccount);
					}
					if(agent != null){
						
						CMD_ChipInfo cmd = new CMD_ChipInfo();
						cmd.m_lUid = (long) creator;
						cmd.m_lTotalCoin = (long) user.getCoin(0);
						cmd.m_lTotalGem = (long) user.getGem(0);
						cmd.m_lTicket = 0L;

						String sData = cmd.getJsonData();
						dthall.getInstance().onSend(user.getUid(), sData);
						
						CMD_S_HALL_NEED_LOGOUT logout = new CMD_S_HALL_NEED_LOGOUT();
						logout.reason = "need logout";
						String logoutData = logout.getJsonData();
						dthall.getInstance().onSend(user.getUid(), logoutData);

						LogicServer.getInstance().unlockUserWithRoom(agent,value.GetID());
						LogicServer.getInstance().afterQuitRoom(LogicServer.getUserAccount(agent));
						LogicServer.getInstance().onUserLogout(String.valueOf(user.getUid()));
						LogicServer.getInstance().onUserLogout(user.m_sAccount);
					}
				}
			}
		}
		
		Iterator<Map.Entry<Integer, IRoom>> itRoom = m_mapRoom.entrySet().iterator();
		while (itRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				System.out.println("delete this: " + key + " = " + key);
				itRoom.remove();

				LogicServer.getInstance().afterDestoryRoom(String.valueOf(value.GetCreator()),value.GetID(),value.getStatus());
				if(value.getClubId() != 0){
					//在俱乐部内
					ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomDismiss(value.getClubId(),value.GetID());
				}
			}
		}
		m_mapFZ.remove(tbl.GetID());
		//发布消息
		JSONObject pub = new JSONObject();
		pub.put("command","pub_dissmiss_club_name");
		pub.put("value1",roomid);
		ClubRedis.getInstance().pubClubSubMsg(pub);
	}
	public void OnDismissRoom(IRoom tbl) {
		if (tbl == null)
			return;
		int roomid = tbl.GetID();
		Integer creator = tbl.GetCreator();
		if (creator > 10) {
			SHMUser user = dthall.getInstance().getUserInfo(creator);
			if (user != null) {
				CMD_ChipInfo cmd = new CMD_ChipInfo();
				cmd.m_lUid = (long) creator;
				cmd.m_lTotalCoin = (long) user.getCoin(0);
				cmd.m_lTotalGem = (long) user.getGem(0);
				cmd.m_lTicket = 0L;

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(creator, sData);
			}
		}

		Iterator<Map.Entry<Integer, IRoom>> itUserRoom = m_mapUserRoom.entrySet().iterator();
		while (itUserRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itUserRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				System.out.println("delete this: " + key + " = " + key);
				itUserRoom.remove();
				SHMUser user = dthall.getInstance().getUserInfo(key);
				if(user != null){
					GameAgent agent = LogicServer.getUserAgent("" + user.getUid());
					if(agent == null){
						agent = LogicServer.getUserAgent("" + user.m_sAccount);
					}
					if(agent != null){
						LogicServer.getInstance().unlockUserWithRoom(agent,value.GetID());
						LogicServer.getInstance().afterQuitRoom(LogicServer.getUserAccount(agent));
					}
				}
			}
		}
		
		Iterator<Map.Entry<Integer, IRoom>> itRoom = m_mapRoom.entrySet().iterator();
		while (itRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				System.out.println("delete this: " + key + " = " + key);
				itRoom.remove();

				if(value.GetID() != 0){
					LogicServer.getInstance().afterDestoryRoom(String.valueOf(value.GetCreator()),value.GetID(),value.getStatus());
					if(value.getClubId() != 0){
						//在俱乐部内
						ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomDismiss(value.getClubId(),value.GetID());
					}
				}
			}
		}
		m_mapFZ.remove(tbl.GetID());
		//发布消息
		JSONObject pub = new JSONObject();
		pub.put("command","pub_dissmiss_club_name");
		pub.put("value1",roomid);
		ClubRedis.getInstance().pubClubSubMsg(pub);
	}
	public boolean hasSuchRoom(int roomid){
		return m_mapRoom.containsKey(roomid);
	}
	public void NotifyRemoveUserRoom(IRoom tbl) {

		Iterator<Map.Entry<Integer, IRoom>> itUserRoom = m_mapUserRoom.entrySet().iterator();
		while (itUserRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itUserRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (value.GetID() == tbl.GetID()) {
				itUserRoom.remove();
				CMD_S_DissmissRoom cmd = new CMD_S_DissmissRoom();
				cmd.uid = key;
				cmd.cbResult = 0;
				cmd.room_id = value.GetID();

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(key, sData);
				
				SHMUser user = dthall.getInstance().getUserInfo(key);
				if(user != null){
					GameAgent agent = LogicServer.getUserAgent("" + user.getUid());
					if(agent != null){
						LogicServer.getInstance().unlockUserWithRoom(agent,value.GetID());			
						LogicServer.getInstance().afterQuitRoom(LogicServer.getUserAccount(agent));			
					}
				};
			}
		}
	}

	public void OnRemoveUserRoom(int _Uid) {
		Iterator<Map.Entry<Integer, IRoom>> itUserRoom = m_mapUserRoom.entrySet().iterator();
		while (itUserRoom.hasNext()) {
			Map.Entry<Integer, IRoom> entry = itUserRoom.next();
			Integer key = entry.getKey();
			IRoom value = entry.getValue();
			if (key == _Uid) {
				CMD_S_UserRoom cmd = new CMD_S_UserRoom();

				cmd.uid = key;
				cmd.room_id = 0;

				String sData = cmd.getJsonData();
				dthall.getInstance().onSend(key, sData);
				itUserRoom.remove();

				if(value.getClubId() != 0){
					ClubMgr.getInstance().m_clubHandler.handleOn_ClubRoomUserLeave(value.getClubId(),value.GetID(),_Uid);
				}

				GameAgent agent = LogicServer.getUserAgent("" + _Uid);
				if(agent != null){
					LogicServer.getInstance().unlockUserWithRoom(agent,value.GetID());
					LogicServer.getInstance().afterQuitRoom(LogicServer.getUserAccount(agent));
				}
			}
		}
	}
	private void onDealSG(GameAgent agent, JSONObject root, String mode) {

	}

	private void onDealSLWH(GameAgent agent, JSONObject root, String mode) {

	}
	public void onDealZJH10(GameAgent agent, JSONObject root, String mode) {		
		Server.Poker.ZJH10.ZjhTable10Mgr.OnRecv(agent, root);		
	}
	public void onDealZJH(GameAgent agent, JSONObject root, String mode) {		
		Server.Poker.ZJH.ZjhTableMgr.OnRecv(agent, root);		
	}
	
	private void onDealNN(GameAgent agent, JSONObject root, String mode) {
		Server.Poker.NiuNiu.niuniuTableMgr.OnRecv(agent, root);
	}
	private void onDealNN10(GameAgent agent, JSONObject root, String mode) {
		Server.Poker.NiuNiu10.niuniuTable10Mgr.OnRecv(agent, root);
	}
	private void onDealFJSSZ(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				Server.Poker.FJSSZ.SSZTableMgr.OnRecv(agent, root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}		
	}
	private void onDealSSZLIU(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				Server.Poker.SSZLIU.SSZTableMgr.OnRecv(agent, root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}		
	}
	
	private void onDealDDZ(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				Server.Poker.DDZ.DDZTableMgr.getInstance().OnRecv(agent.CID, agent.getUid(), root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	private void onDealPDK(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				Server.Poker.PDK.PDKTableMgr.getInstance().OnRecv(agent.CID, agent.getUid(), root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}		
	}
	private void onDealNTPDK(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				Server.Poker.NTPDK.PDKTableMgr.getInstance().OnRecv(agent.CID, agent.getUid(), root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}		
	}
	private void onDealCP(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				Server.Jsmj.RGCP.RGCPTableMgr.instance().OnRecv(agent ,root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}		
	}
	private void onDealSJ(GameAgent agent, JSONObject root,String mode){
		try
		{
			Integer lUid = agent.getUid();
			if(lUid > 0)
			{
				//Server.Jsmj.RGCP.RGCPTableMgr.instance().OnRecv(agent.CID, agent.getUid(), root);
			}
		}catch(Exception e)
		{
			e.printStackTrace();
		}		
	}
	private void onDealTTZ(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if (tbl != null) {
						String room_type = tbl.GetType();
						if(room_type.equals("TTZ")){
							Server.Poker.TTZ.TTZTableMgr.OnRecv(agent, root);
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void onDeaBJZ(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						if(room_type.equals("LABJ")){
							Server.Poker.LABJZ.BJZTableMgr.getInstance().OnRecv(agent, root);
						}else{
							Server.Poker.BJZ.BJZTableMgr.getInstance().OnRecv(agent, root);
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public void onDeaDGT(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Poker.DGT.DGTTableMgr.getInstance().OnRecv(agent.CID, agent.getUid(), root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public void onDwcSGJ(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.fksgj.fksgjTableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public void onDwcBrSGJ(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.brsgj.brsgjTableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public void onDwcFkFish(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.brsgj.brsgjTableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public void onDwcSlhb(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.slhb.SlhbTableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public void onDwcCqssc(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.cqssc.CqsscTableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void onDwcPK10(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.pk10.pk10TableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void onAzxy5(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if(tbl != null){
						String room_type = tbl.GetType();
						Server.Dwc.azxy5.Azxy5TableMgr.OnRecv(agent, root);
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public void onDealMJ(GameAgent agent, JSONObject root, String mode) {
		try {
			Integer lUid = agent.getUid();
			if (lUid > 0) {
				if (m_mapUserRoom.containsKey(lUid)) {
					IRoom tbl = m_mapUserRoom.get(lUid);
					if (tbl != null) {
						String room_type = tbl.GetType();
						if (room_type.equals("HQMJ")) {
							Server.AHMJ.HQMJ.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("LAMJ")) {
							Server.AHMJ.LAMJ.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("LAHZ")) {
							Server.AHMJ.LAHZ.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("SCMJ")) {
							Server.AHMJ.SCMJ.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("SCDB")) {
							Server.AHMJ.SCDB.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("HFHZ")) {
							Server.AHMJ.HFHZ.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("HFMJ")) {
							Server.AHMJ.HFMJ.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("HFSR")) {
							Server.AHMJ.HFSR.MajTableMgr.OnRecv(agent, root);
						}else if (room_type.equals("HFMJ")) {
							Server.AHMJ.HFSR.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("NIUNIU")){
							Server.Poker.NiuNiu.niuniuTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("HNNIUNIU")){
							Server.Poker.HnNiuNiu.niuniuTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("HZMJ")){
							Server.Hnmj.HZMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("CBDD")){
							Server.Hbmj.CBDDMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("XXMJ")){
							Server.Hnmj.XXMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("ZZMJ")){
							Server.Hnmj.ZZMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("JZMJ")){
							Server.AHMJ.JZMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("YJMJ")){
							Server.AHMJ.YJMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("HSMJ")){
							Server.AHMJ.HSMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("MDMJ")){
							Server.AHMJ.MDMJ.MajTableMgr.OnRecv(agent, root);
						}else if(room_type.equals("DGT")){
							Server.Poker.DGT.DGTTableMgr.getInstance().OnRecv(agent.CID, agent.getUid(), root);
						}
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}	
	}
	public boolean OnRecv(GameAgent agent,JSONObject root){
		String command = root.optString("command");
		String mode = root.optString("mode");
		switch(command){
		case "zjhmsg10":
			onDealZJH10(agent, root, mode);
			break;
		case "zjhmsg":
			onDealZJH(agent, root, mode);
			break;
		case "xlchmsg":
			onDealMJ(agent, root, mode);
			break;
		case "niuniumsg":
			onDealNN(agent, root, mode);
			break;
		case "niuniumsg10":
			onDealNN10(agent, root, mode);
			break;
		case "sgmsg":
			onDealSG(agent, root, mode);
			break;
		case "slwhmsg":
			onDealSLWH(agent, root, mode);
			break;
		case "ttzmsg":
			onDealTTZ(agent, root, mode);
			break;
		case "fjsszmsg":
			onDealFJSSZ(agent, root,mode);
			break;
		case "sszliumsg":
			onDealSSZLIU(agent, root,mode);
			break;
		case "ddzmsg":
			onDealDDZ(agent, root,mode);
			break;
		case "pdkmsg":
			onDealPDK(agent, root,mode);
			break;
		case "ntpdkmsg":
			onDealNTPDK(agent, root,mode);
			break;
		case "cpmsg":
			onDealCP(agent, root,mode);
			break;
		case "sjmsg":{
			onDealSJ(agent, root,mode);
			break;
		}
		case "mjmsg":
			onDealMJ(agent, root, mode);
			break;
		case "bjzmsg":
			onDeaBJZ(agent, root, mode);
			break;
		case "dgtmsg":
			onDeaDGT(agent, root, mode);
			break;
		case "fksgjmsg":
			onDwcSGJ(agent,root,mode);
			break;
		case "brsgjmsg":
			onDwcBrSGJ(agent,root,mode);
			break;
		case "FGRoomList":
			onDealFangGuanGetRoomList(agent);
			break;
		case "fkfishmsg":
			onDwcFkFish(agent,root,mode);
			break;
		case "slhbmsg":
			onDwcSlhb(agent,root,mode);
			break;
		case "cqsscmsg":
			onDwcCqssc(agent,root,mode);
			break;
		case "pk10msg":
			onDwcPK10(agent,root,mode);
		case "dhsscmsg":
			onAzxy5(agent,root,mode);
		}
		return true;
	}
}
